<?php
/**
 * 文章列表
 *
 */
function & li($page_size = ADM_PAGESIZE) {
    global $_TABLES, $class_var, $cata_info, $timestamp,$G_admin_session_key;

    $view_var   = array();
    $tbl_main   = $_TABLES['article'];

    $conn   = & get_db_conn();
    $where      = 'WHERE 1 ';
    // 关键字
    $key    = trim(@$_GET['key']);
    if($key != '') $where  .= "AND (a.article_title LIKE '%$key%' OR a.keywords LIKE '%$key%' OR a.brief LIKE '%$key%' OR a.content LIKE '%$key%' )";

    // 分类
    $cata   = @(int)$_GET['cata'];
    $cid    = @(int)$_GET['cid'];
    $sub    = @(int)$_GET['sub'];
    if($sub == 1) {
        $where  .= "AND a.cid = $cid ";
    } else {
        // 显示当前分类及其子分类下的文章
        $cid    = find_subnode_id($cid, $GLOBALS[$class_var]) . $cid;
        $where  .= "AND a.cid IN ($cid) ";
    }
    if($cata > 0) {
        // 显式指定了栏目id
        $where  .= "AND a.cata_id = $cata ";
    }
    // 审核
    $display = @(int)$_GET['display'];
    if($display == 1) {
        $where  .= "AND a.display = 1 ";
    } elseif($display == 2) {
        $where  .= "AND a.display = 0 ";
    }

    $is_ad  = @$_GET['is_ad'];
    if($is_ad == 1) {
        // 发布时间处理开始
        $begin_date = @$_GET['begin_date'];
        $end_date   = @$_GET['end_date'];
        if($begin_date == '') {
            $begin_date   = 0;
        } else {
            $tmp    = explode('-', $begin_date);
            $begin_date = mktime(0 ,0, 0,$tmp[1] ,$tmp[2], $tmp[0]);
        }
        if($end_date == '') {
            $end_date   = $timestamp;
        } else {
            $tmp        = explode('-', $end_date);
            $end_date   = mktime(23 ,59, 59,$tmp[1] ,$tmp[2], $tmp[0]);
        }
        $where .= "AND (a.pub_time >= '$begin_date' AND a.pub_time <= '$end_date' ) ";
        // 发布时间处理结束
        $top        = @(int)$_GET['top'];
        $flag       = 0;
        if(!empty($_GET['flag']) && is_array($_GET['flag'])) {
            foreach($_GET['flag'] as $f) {
                $flag += @(int)$f;
            }
        }
        if($top == 1) {
            $where .= "AND a.top = 1 ";
        }
        if($flag > 0) {
            $where .= "AND a.flag & $flag = $flag ";
        }
    }
    // 分页处理开始
    $csql   = "SELECT COUNT(*) AS rs_count FROM $tbl_main a $where";
    $rs     = $conn->GetOne($csql);

    $record_total   = @(int)$rs;
    $page_total     = ceil($record_total/$page_size);

    $page   = @(int)$_GET['page'];
    if($page < 1) $page = 1;
    if($page > $page_total && $page_total > 0) $page = $page_total;
    $offset = ($page - 1) * $page_size;
    $limit  = "LIMIT $offset, $page_size";

    $view_var['record_total']   = $record_total;
    $view_var['page_total']     = $page_total;
    $view_var['page']           = $page;
    $view_var['page_size']      = $page_size;
    // 分页处理完毕


    // 列表处理开始
    $order_by   = trim(@$_GET['orderby']);
    $order_desc = @(int)$_GET['desc'];
    
    $order_by_q  = substr($order_by,0,5);
    $order_by_h  = substr($order_by,5);

    if($order_by_q   == 'flag_') {
        $order_by   = $order_by_h;
    }
    $select_param   = '';
    $str_order_by   = '';
    if($order_by != '') {
        if($order_by > 0) {
            $order_desc = ($order_desc!=1)?'DESC':'ASC';
            $orderfield = 'f' . $order_by;
            $select_param   = ",((`flag` & $order_by ) = $order_by) AS $orderfield";
            $str_order_by   = "{$orderfield} {$order_desc},";
        } else {
            $order_desc = ($order_desc!=1)?'ASC':'DESC';
            $str_order_by = "`{$order_by}` {$order_desc}, ";
        }
    }


    $order  = "";
    if($cata_info['cata_type'] == 1) {
        $order  = "ORDER BY $str_order_by cata_order ASC, a.aid ASC";
    } else {
        $order  = "ORDER BY $str_order_by a.aid DESC";
    }

    $sql    = "SELECT a.aid, a.cid, a.cata_id, a.cata_order, a.article_title, 
            a.display,a.flag,a.tcolor,a.small_image,a.big_image,
            a.pub_userid, a.pub_username, a.pub_realname, a.pub_time,a.top,a.type,a.sqcs,a.createtime $select_param
            FROM $tbl_main as a $where $order";
    //echo $sql;
    $rs = & $conn->PageExecute($sql,$page_size,$page);
    $view_var['record'] = $rs->GetRows();

    return $view_var;
}


function & read($id = 0) {
    global $_TABLES, $timestamp, $mod, $G_admin_session_key, $G_cfg, $G_big_integer;

    $view_var   = array();
    $tbl_main   = $_TABLES['article'];
    
    $tbl_special_rel= $_TABLES['article_params'];
    
    $tbl_zone   = $_TABLES['city'];
    if($id > 0) {
        $conn       = & get_db_conn();
        $view_var   = $conn->GetRow("SELECT * FROM $tbl_main WHERE aid = $id");
        if($view_var['cid']==6||$view_var['cid']==7||$view_var['cid']==8||$view_var['cid']==9||$view_var['cid']==10){
            $tbl_special_rel.='_'.$view_var['cid'];
        }
        
        $view_var['pars']   = $conn->GetRow("SELECT * FROM $tbl_special_rel WHERE aid = $id");
        
        $sql1="SELECT * FROM $tbl_zone where id={$view_var['city']}";
        $view_var['city'] = & $conn->GetRow($sql1);
        if($view_var['city']['num']==0&&$view_var['city']['num1']==0){//一级
            $view_var['city1']=$view_var['city'];
        }elseif($view_var['city']['num']!=0&&$view_var['city']['num1']==0){//二级
            $sql1="SELECT * FROM $tbl_zone where id={$view_var['city']['num']}";
            $view_var['city1'] = & $conn->GetRow($sql1);
            $view_var['city2'] = $view_var['city'];
        }else{//三级
            $sql1="SELECT * FROM $tbl_zone where id={$view_var['city']['num']}";
            $view_var['city1'] = & $conn->GetRow($sql1);
            $sql1="SELECT * FROM $tbl_zone where id={$view_var['city']['num1']}";
            $view_var['city2'] = & $conn->GetRow($sql1);
            $view_var['city3'] = $view_var['city'];
        }
    } else {
		$pub_userid    = $_SESSION[$G_admin_session_key]['uid'];
        $pub_username  = $_SESSION[$G_admin_session_key]['username'];
        $pub_realname  = $_SESSION[$G_admin_session_key]['realname'];
        // 看用户是否有审核权限
        $chk_userid    = $_SESSION[$G_admin_session_key]['uid'];
        $chk_username  = $_SESSION[$G_admin_session_key]['username'];
        $chk_realname  = $_SESSION[$G_admin_session_key]['realname'];

        $view_var   = array('display' => $G_cfg['article_cfg']['article_display_default'],
                'top'     => 0,
                'new'     => 0,
                'recommend'=> 0,
                'brief'   => '',

              'pub_userid'      => $pub_userid,
              'pub_username'    => $pub_username,
              'pub_realname'    => $pub_realname,
              'pub_time'        => $timestamp,
              'createtime'     => $timestamp,
              'modifytime'      => $timestamp,
              'chk_userid'      => $chk_userid,
              'chk_username'    => $chk_username,
              'chk_realname'    => $chk_realname,
              'chk_time'        => $timestamp,);
    }
    return $view_var;
}


/**
 * @description
 *  文章详细内容，
 *  获取参数，验证参数，初始化参数
 * @author
 *  hotgun@163.com
 *
 * @param
 *  (integer)$upload 是否包含并处理上传部分，如果是单独审核的就不需要包含这块，
 * @return 
 *  (array)修改和添加能使用的数组
 */
function & request($upload = 1) {
    global $action, $timestamp, $G_big_integer, $_TABLES,$content_class_cache;

    $data   = $_POST['article'];
    $tbnum='params';
    if($data['cid']==6||$data['cid']==7||$data['cid']==8||$data['cid']==9||$data['cid']==10){
        $tbnum.=$data['cid'];
    }
    
	$data['params']   = $data[$tbnum];
    
	$cata	= @(int)$data['cata'];		// 栏目
	$data['endTime']  = strtotime($data['endTime']);
    $data['display']  = @(int)$data['display']; // 审核
    $data['type']	= @(int)$data['type']; // 
    $data['zd_type']	= @(int)$data['zd_type']; // 
    $data['jd_type']	= @(int)$data['jd_type']; // 
    // 获取文章属性
    $flag   = 0;
    if(!empty($data['flag']) && is_array($data['flag'])) {
        foreach($data['flag'] as $flagv) {
            $flag  += @(int)$flagv;
        }
    }
    $data['flag']   = $flag;
    $data['guapai']   = @(int)$data['guapai'];

    if($data['num3']){
        $data['city']=$data['num3'];
    }elseif($data['num2']){
        $data['city']=$data['num2'];
    }elseif($data['num1']){
        $data['city']=$data['num1'];
    }else{
        $data['city']=0;
    }
    unset($data['num1']);
    unset($data['num2']);
    unset($data['num3']);
    
    // 附件
    // $data['att']
    if(@(int)$data['chk_outeratt'] == 1) {
        // 如果使用外部链接
        $data['att'] = '';
        $data['outeratt'] = trim($data['outeratt']);
    } else {
        $data['outeratt'] = '';
        // 分析 att
        $att = '';
        if(!empty($data['att']) && is_array($data['att'])) {
            foreach($data['att'] as $v) {
                if($v == '') continue;
                $att .= $v . '|';
            }
        }
        if($att != '') $att = substr($att, 0, strlen($att)-1);
        $data['att'] = $att;
    }

    // 如果是修改，获得当前文章的图片id
    // small_image_modaid
    if($action == 'modify') {
        $data['small_image_modaid'] = GetGP('small_image_modaid');
        $data['big_image_modaid']   = GetGP('big_image_modaid');
    }

    $data['cata_order'] = @(int)$data['cata_order'];
    if($data['cata_order'] <= 0 || $data['cata_order'] >= $G_big_integer) $data['cata_order'] = $G_big_integer;


    $arr    = explode('-', $data['pub_date']);
    if(sizeof($arr) == 3) {
        $data['pub_hour']   = @(int)$data['pub_hour'];
        $data['pub_min']    = @(int)$data['pub_min'];
        $data['pub_sec']    = @(int)$data['pub_sec'];
        $data['pub_time']   = mktime($data['pub_hour'] ,$data['pub_min'], $data['pub_sec'],$arr[1] ,$arr[2], $arr[0]);
    } else {
        $data['pub_time']   = $timestamp;
    }

    // 处理单双引号等问题
    $data = post_pre_process($data);


    // 过滤HTML内容中被php转义后的字符 
    // 去掉双引号前的转移符，将转义后的单引号转换成&#39;
    if(isset($data['content']))
	$data['content']    = str_replace("\\\"", "\"", str_replace("\\'", "&#39;", $data['content']));
    // 摘要的双引号不转义，单引号转成&#39;
    
	if(isset($data['brief']))
	$data['brief']      = str_replace("\\\"", "\"", str_replace("\\'", "&#39;", $data['brief']));
    
    $rule = array();
    $def_err = array();
    if($upload == 1) {
        $rule   = array(
            'article_title' => 'i_string|len:1:255',
            'endTime' => 'i_string|len:1:255',
            'price'           => 'i_float|len:1:255', 
            'price_pg'   => 'i_empty|i_float'
            );

        // 验证正确性
        $def_err= array(
            'article_title' => '“标题”必须填写，且长度必须在1～255个字符之间！',
            'endTime' => '“信息有效期”必须填写！',
            'price'           => '“挂牌价”不能为空，且只能填写数字',
            'price_pg'           => '“评估价”只能填写数字',  
            );
    }
    
    
    $makethumb  = @(int)$data['makethumb'];
    if($makethumb ==  1) {
        $makethumbwidth     = @(int)$data['makethumbwidth'];
        $makethumbheight    = @(int)$data['makethumbheight'];
    } else {
        $makethumbwidth     = '';
        $makethumbheight    = '';
    }
    $result = data_validator($data, $rule, $def_err);
    if($result === true) {
        // 其他逻辑错误检验
    } else {
        foreach($result as $v) {
            $GLOBALS['ERR']->AddError(_ERROR_BUSINESS, 
                        $v, 
                        __FILE__,
                        __LINE__);
        }
    }
    if($GLOBALS['ERR']->Count > 0) {
        return false;
    } else {
        
        // 处理小图/大图上传等问题
        if($upload == 1) {
            global $mod, $G_abs_includes;
            require($G_abs_includes . '/upload.php');
            $up = upload_files($mod,$makethumbwidth,$makethumbheight);
            $data['up_small_image']= empty($up['small_image']) ? '' : $up['small_image'];
            $data['up_big_image']  = empty($up['big_image']) ? '' : $up['big_image'];
        }
        return $data;
    }
}


/**
 * @description
 *  验证分类id的合法性
 * @author
 *  hotgun@163.com
 *
 * @return 
 *  (array)供主控部分使用的返回数据
 */
function & get_artcid($cid, $cata) {
    global $_TABLES;

    $arr        = array();
    $tbl_main   = $_TABLES['article_class'];
    $conn       = & get_db_conn();
    $rs = $conn->GetOne("SELECT COUNT(*) AS rs_count FROM $tbl_main WHERE cid = '$cid'");
    if(!$rs) $cid = 0;

    if($cata > 0 && $cid == 0) {
        $arr['cata_id'] = $cata;
        $arr['cid']     = $cata;
    } else {
        $arr = array(
            'cid' => $cid,
            'cata_id' => $cata,
            );
    }
    return $arr;
}

function not_samerecord($cid, $title, $modify = 0) {
    global $_TABLES;

    $tbl_main   = $_TABLES['article'];
    $conn       = & get_db_conn();
    $where      = '';
    if($modify != 0)  $where = "AND aid <> $modify ";

    $rs = $conn->GetRow("SELECT COUNT(*) AS rs_count FROM $tbl_main WHERE article_title = '$title' AND cid = '$cid' $where ");
    if($rs['rs_count'] > 0) {
        $GLOBALS['ERR']->AddError(_ERROR_BUSINESS, 
                "系统当前分类中已经存在标题为<FONT COLOR=\"red\">{$title}</FONT>的文章，无法当前操作！", 
                __FILE__,
                __LINE__);
        return false;
    }
    return true;
}


function check_record($aid, $table) {
    global $_TABLES;

    $tbl_main   = $_TABLES[$table];
    $conn       = & get_db_conn();
    $where      = '';
    if($aid > 0)  $where = "AND aid = $aid ";

    $rs = $conn->GetRow("SELECT COUNT(*) AS rs_count FROM $tbl_main WHERE 1 $where ");
    if($rs['rs_count'] > 0) {
        return true;
    }
    return false;
}



/**
 * @description
 *  添加文章内容
 * @author
 *  hotgun@163.com
 *
 * @return 
 *  (array)供主控部分使用的返回数据
 */
function add() {
    global $_TABLES, $timestamp, $mod, $class_var, $G_admin_session_key, $G_cfg;

    $tbl_article        = $_TABLES['article'];
    $tbl_article_class  = $_TABLES['article_class'];
    $tbl_attachments    = $_TABLES['attachments'];

    $result = & request();
    if($result !== false) {
        $conn   = & get_db_conn();
        if($result['gsid'] > 0 && $result['cid'] == -1) {
            // 如果显式指明当前分类不属于任何其他文章分类，只是属于某个专题的内容
            $result['cid']      = -1;
            $result['cata_id']  = -1;
        } else {
            $cidarr = & get_artcid($result['cid'], $result['cata']);
            $result['cid']      = $cidarr['cid'];
            $result['cata_id']  = $cidarr['cata_id'];
        }

        if(not_samerecord($result['cid'], $result['article_title'])) {
            // 如果没有同名纪录
            // 创建者/审核者等数据
            $result['pub_userid']   = $_SESSION[$G_admin_session_key]['uid'];
            $result['pub_username'] = $_SESSION[$G_admin_session_key]['username'];
            $result['pub_realname'] = $_SESSION[$G_admin_session_key]['realname'];

            if(1) {
                // 有审核权限
                $result['chk_userid']   = $_SESSION[$G_admin_session_key]['uid'];
                $result['chk_username'] = $_SESSION[$G_admin_session_key]['username'];
                $result['chk_realname'] = $_SESSION[$G_admin_session_key]['realname'];
                $result['chk_time']     = $timestamp;
            }
            $result['createtime']  = $timestamp;
            $result['modifytime']   = $timestamp;

            // 初始化图片字段
            $result['small_image']      = '';
            $result['small_image_aid']  = 0;
            $result['small_images']     = '';
            $result['big_image']        = '';
            $result['big_image_aid']    = 0;
            $result['big_images']       = '';





            if($conn->AutoExecute($tbl_article,$result,'INSERT')) {
                $aid    = $conn->Insert_ID();
                if($aid){
                    $name=$_SESSION[$G_admin_session_key]['username'];
                    if($_SESSION[$G_admin_session_key]['realname']){
                        $name=$_SESSION[$G_admin_session_key]['realname'];
                    }
                }
                // 同步图片信息
                $images = array(
                    'small_image' => $result['up_small_image'],
                    'big_image' => $result['up_big_image'],
                    );
                $tbl = array('tbl'=>$tbl_article,'pk'=>'aid');
                syn_article_images($aid, $images, $tbl);
                // 同步专题信息
                syn_article_special($result['sid'], $result['scid'], $aid );
                // 同步自定义参数
                if($result['defparam']) {
                    content_param($aid, $result['defparam']);
                }

				$params_arr	= $result['params'];	// 数组记录
				$params_arr['aid']	= $aid;
				// 同步处理参数
                $tn='article_params';
                if($result['cid']==6||$result['cid']==7||$result['cid']==8||$result['cid']==9||$result['cid']==10){
                    $tn.='_'.$result['cid'];    
                }
                if(!$params_arr['order_no']){
                    $params_arr['order_no']='';
                    if($result['cid']==6){
                        $params_arr['order_no'].='GD';
                    }elseif($result['cid']==7){
                        $params_arr['order_no'].='ZQ';
                    }elseif($result['cid']==8){
                        $params_arr['order_no'].='GQ';
                    }elseif($result['cid']==9){
                        $params_arr['order_no'].='RZ';
                    }elseif($result['cid']==10){
                        $params_arr['order_no'].='WX';
                    }else{
                        $params_arr['order_no'].='QT';
                    }
                    $n=strtotime(date('Y-m-d 00:00:00',time()));
                    $params_arr['order_no'].=substr(date('Ymd',time()),2);
                    $co=$conn->GetRow("SELECT p.order_no FROM $tbl_article a left join {$_TABLES[$tn]} p on p.aid=a.aid WHERE length(p.order_no)=10 and a.modifytime>=$n order by p.order_no desc limit 1");
                    //$co=$conn->GetRow("SELECT COUNT(*) co FROM $tbl_article WHERE modifytime>=$n ");
                    if(!$co['order_no']){
                        $params_arr['order_no'].='00';
                    }else{
                        $nm=(@(int)substr($co['order_no'],8))+1;
                        if($nm<10){
                            $nm='0'.$nm;
                        }
                        $params_arr['order_no'].=$nm;
                    }
                }
				if(check_record($aid,$tn)) {	// 如果已存在记录，修改
					$conn->AutoExecute($_TABLES[$tn],$params_arr,'UPDATE', 'aid=' . $aid );
				} else {
				    $conn->Execute("DELETE FROM {$_TABLES['article_params']} WHERE aid IN ({$aid}) ");
                    $conn->Execute("DELETE FROM {$_TABLES['article_params_6']} WHERE aid IN ({$aid}) ");
                    $conn->Execute("DELETE FROM {$_TABLES['article_params_7']} WHERE aid IN ({$aid}) ");
                    $conn->Execute("DELETE FROM {$_TABLES['article_params_8']} WHERE aid IN ({$aid}) ");
                    $conn->Execute("DELETE FROM {$_TABLES['article_params_9']} WHERE aid IN ({$aid}) ");
                    $conn->Execute("DELETE FROM {$_TABLES['article_params_10']} WHERE aid IN ({$aid}) ");
					$conn->AutoExecute($_TABLES[$tn],$params_arr,'INSERT');
				}
                // 返回到控制器的内容
                $re = array('aid'=>$aid,'cid'=>$result['cid'],'gsid'=>$result['gsid']);
                return $re;
            }
        }
    }
    return false;
}


function modify() {
    global $_TABLES, $timestamp, $class_var, $G_admin_session_key;

    $tbl_article        = $_TABLES['article'];
    $tbl_article_class  = $_TABLES['article_class'];

    $result = & request();
    if($result !== false) {
        $conn   = & get_db_conn();

        // 验证分类ID的合法性，如果不存在，分类ID=0
        if($result['gsid'] > 0 && $result['cid'] == -1) {
            // 如果显式指明当前分类不属于任何其他文章分类，只是属于某个专题的内容
            $result['cid']      = -1;
            $result['cata_id']  = -1;
        } else {
            $cidarr = & get_artcid($result['cid'], $result['cata']);
            $result['cid']      = $cidarr['cid'];
            $result['cata_id']  = $cidarr['cata_id'];
        }

        // 先查看是否有同名记录
        if(not_samerecord($result['cid'], $result['article_title'], $result['aid'])) {
            // 如果没有同名纪录
            // 得到当前文章状态
            $sql    = "SELECT display,
                                small_image, small_image_aid, small_images,
                                big_image, big_image_aid, big_images
                        FROM $tbl_article 
                        WHERE aid = '{$result['aid']}' ";
            $old_a  = $conn->GetRow($sql);
            // 获得小图原始信息
            $old_small_images   = $old_a['small_images'];
            // 获得大图原始信息
            $old_big_images     = $old_a['big_images'];


            if(1) {
                // 有审核权限
                $result['chk_userid']   = $_SESSION[$G_admin_session_key]['uid'];
                $result['chk_username'] = $_SESSION[$G_admin_session_key]['username'];
                $result['chk_realname'] = $_SESSION[$G_admin_session_key]['realname'];
                $result['chk_time']     = $timestamp;
            }

            $result['modify_time']  = $timestamp;
            // 清除上面可能的如下参数传递
            unset($result['small_image']);
            unset($result['small_image']);
            unset($result['small_image_aid']);
            unset($result['small_images']);
            unset($result['big_image']);
            unset($result['big_image_aid']);
            unset($result['big_images']);
            $result['modifytime']      = $timestamp;
            if($conn->AutoExecute($tbl_article,$result,'UPDATE', 'aid=' . $result['aid'] )) {
                // 同步图片信息
                $aid=$result['aid'];
                $images = array(
                    'small_image' => $result['up_small_image'],
                    'big_image' => $result['up_big_image'],
                    );
                $tbl = array('tbl'=>$tbl_article,'pk'=>'aid');
                syn_article_images($result['aid'], $images, $tbl);
                // 同步专题信息
                syn_article_special($result['sid'], $result['scid'], $result['aid']);
                // 同步自定义参数
                if($result['defparam']) {
                    content_param($result['aid'], $result['defparam']);
                }
				$params_arr	= $result['params'];	// 数组记录
				$params_arr['aid']	= $result['aid'];
				
                $tn='article_params';
                if($result['cid']==6||$result['cid']==7||$result['cid']==8||$result['cid']==9||$result['cid']==10){
                    $tn.='_'.$result['cid'];    
                }
                
                if(!$params_arr['order_no']){
                    $params_arr['order_no']='';
                    if($result['cid']==6){
                        $params_arr['order_no'].='GD';
                    }elseif($result['cid']==7){
                        $params_arr['order_no'].='ZQ';
                    }elseif($result['cid']==8){
                        $params_arr['order_no'].='GQ';
                    }elseif($result['cid']==9){
                        $params_arr['order_no'].='RZ';
                    }elseif($result['cid']==10){
                        $params_arr['order_no'].='WX';
                    }else{
                        $params_arr['order_no'].='QT';
                    }
                    $n=strtotime(date('Y-m-d 00:00:00',time()));
                    $params_arr['order_no'].=substr(date('Ymd',time()),2);
                    $co=$conn->GetRow("SELECT p.order_no FROM $tbl_article a left join {$_TABLES[$tn]} p on p.aid=a.aid WHERE length(p.order_no)=10 and a.modifytime>=$n order by p.order_no desc limit 1");
                    //$co=$conn->GetRow("SELECT COUNT(*) co FROM $tbl_article WHERE modifytime>=$n ");
                    if(!$co['order_no']){
                        $params_arr['order_no'].='00';
                    }else{
                        $nm=(@(int)substr($co['order_no'],8))+1;
                        if($nm<10){
                            $nm='0'.$nm;
                        }
                        $params_arr['order_no'].=$nm;
                    }
                }
                
				if(check_record($aid,$tn)) {	// 如果已存在记录，修改
					$conn->AutoExecute($_TABLES[$tn],$params_arr,'UPDATE', 'aid=' . $aid );
				} else {
				    $conn->Execute("DELETE FROM {$_TABLES['article_params']} WHERE aid IN ({$aid}) ");
                    $conn->Execute("DELETE FROM {$_TABLES['article_params_6']} WHERE aid IN ({$aid}) ");
                    $conn->Execute("DELETE FROM {$_TABLES['article_params_7']} WHERE aid IN ({$aid}) ");
                    $conn->Execute("DELETE FROM {$_TABLES['article_params_8']} WHERE aid IN ({$aid}) ");
                    $conn->Execute("DELETE FROM {$_TABLES['article_params_9']} WHERE aid IN ({$aid}) ");
                    $conn->Execute("DELETE FROM {$_TABLES['article_params_10']} WHERE aid IN ({$aid}) ");
					$conn->AutoExecute($_TABLES[$tn],$params_arr,'INSERT');
				}

                // 返回到控制器的内容
                $re = array('aid'=>$result['aid'],'cid'=>$result['cid'],'gsid'=>$result['gsid']);
                return $re;
            }
        }
    }
}

/**
 * 查找文章/专题关系
 *
 *
 */
function syn_article_special($sid, $scid, $aid) {
    global $_TABLES;
    $tbl_article_special_rel    = $_TABLES['article_special_rel'];

    $conn   = & get_db_conn();
    // 删除所有关系，加上新的关系
    $conn->Execute("DELETE FROM $tbl_article_special_rel WHERE aid = '$aid'");
    if(is_array($sid)) {
        foreach($sid as $postsid) {
            $postsid = @(int)$postsid;
            $postscid   = @(int)$scid[$postsid];
            $conn->Execute("INSERT INTO $tbl_article_special_rel (sid, scid, aid) VALUES ('$postsid', '$postscid', '$aid')");
        }
    }
}


function reorder() {
    global $_TABLES, $G_big_integer;
    $tbl_article= $_TABLES['article'];

    $item_id = array_join_comma($_POST['item_id']);
    $conn   = & get_db_conn();
    $cata_order = $_POST['cata_order'];
    $sql    = '';
    if(is_array($cata_order) && sizeof($cata_order) > 0) {
        foreach($cata_order as $aid => $order) {
            $order  = @(int)$order;
            if($order <= 0 || $order >= $G_big_integer) $order = $G_big_integer;
            $sql    = "UPDATE $tbl_article SET cata_order = '$order' WHERE aid = '$aid' AND aid IN ($item_id)";
            $conn->Execute($sql);
        }
    }
    js_success('排序成功！');
}


function check_batch($check) {
    global $_TABLES, $timestamp, $class_var, $G_admin_session_key;
    $tbl_article        = $_TABLES['article'];
    $tbl_article_class  = $_TABLES['article_class'];


    if(@(int)$check < 1) {
        $check  = 0;
        $checklang  = '取消审核';
    } else {
        $check  = 1;
        $checklang  = '通过审核';
    }

    $item_id    = array_join_comma($_POST['item_id']);
    if($item_id != '') {
        $conn   = & get_db_conn();
        $sql_append = '';
        if($check == 1) {
            $userid    = $_SESSION[$G_admin_session_key]['userid'];
            $username   = $_SESSION[$G_admin_session_key]['username'];
            $realname   = $_SESSION[$G_admin_session_key]['realname'];
            $sql_append .= "chk_userid = '$userid', chk_username = '$username', chk_realname = '$realname', chk_time = '$timestamp',";
        }


        $update_sql = "update $tbl_article SET 
            $sql_append
            display = $check 
            WHERE aid IN ($item_id)";
        if($conn->Execute($update_sql)) {
            js_success('指定文章' . $checklang . '成功！');
        }
    }
    exit();
}

function move_batch() {
    global $_TABLES, $timestamp, $class_var, $G_admin_session_key;
    $tbl_article        = $_TABLES['article'];
    $tbl_article_class  = $_TABLES['article_class'];

    $item_id    = array_join_comma($_POST['item_id']);
    $move_type  = @(int)$_POST['move_type'];
    $conn   = & get_db_conn();
    if($move_type == 1) {
        $movelang   = '分类';
        // 移动指定文章到分类中
        $move_cid  = @(int)$_POST['move_cid'];
        // 先确定该分类是否存在。如果不存在，则不移动
        $sql = "SELECT cata_id,showid FROM $tbl_article_class WHERE cid = $move_cid LIMIT 0, 1 ";
        $rs  = $conn->GetRow($sql);
        if(@(int)$rs['cata_id'] > 0) {
            // 可以移动
            // 需要重新设置当前分类的栏目ID
            $update_sql = "update $tbl_article SET 
                showid = '" . $rs['showid'] . "',
                cid = '$move_cid',
                cata_id = '" . $rs['cata_id'] . "'
                WHERE aid IN ($item_id)";
        }
    } elseif($move_type == 2) {
        // 移动指定文章到专题中
        $movelang   = '专题';
    }
    if($conn->Execute($update_sql)) {
        js_success('指定文章移动到指定的' . $movelang . '中成功！');
    }
    exit();
}




/**
 * @description
 *  审核单篇文章
 * 
 * @author
 *  hotgun@163.com
 */
function check() {
    global $_TABLES, $timestamp, $class_var, $G_admin_session_key;

    $tbl_article        = $_TABLES['article'];
    $tbl_article_class  = $_TABLES['article_class'];

    $result = request(0);
    if($result !== false) {
        $conn   = & get_db_conn();

        if(@(int)$result['display'] == 1) {
            $result['chk_userid']   = $_SESSION[$G_admin_session_key]['uid'];
            $result['chk_username'] = $_SESSION[$G_admin_session_key]['username'];
            $result['chk_realname'] = $_SESSION[$G_admin_session_key]['realname'];
            $result['chk_time']     = $timestamp;
        } else {
            $result['display'] = 0;
        }
        unset($result['price']);
        unset($result['mprice']);
        unset($result['vprice']);
        unset($result['other_items']);
        unset($result['sid']);
        unset($result['cata_order']);

        if($conn->AutoExecute($tbl_article,$result,'UPDATE', 'aid=' . $result['aid'] )) {
            return $result['aid'];
        }
    }
}


/**
 * @description
 *  查看当前分类中是否有文章, 如果有就取第一篇文章的内容，否则新增一篇,成功后直接跳转
 * 
 * @author
 *  hotgun@163.com
 *
 * @param
 *  (int)$cid 当前分类id
 * @return 
 *  null
 */
function one($cid) {
    global $_TABLES, $mod_url, $timestamp, $cata_info, $G_admin_session_key;
    $tbl_article= $_TABLES['article'];

    $sql= "SELECT aid FROM $tbl_article 
                    WHERE cid = '$cid' 
                 ORDER BY cata_order ASC, aid ASC ";
    $conn   = & get_db_conn();
    $rs     = $conn->GetRow($sql);
    if(!$rs) {
        $rs = array(
            'article_title' => $cata_info['cname'],
            'content' => $cata_info['cname'],
            'cid' => $cid,
            'cata_id' => $cid,
            'createtime' => $timestamp,
            'modifytime' => $timestamp,
            'display' => 1,
            'pub_userid' => $_SESSION[$G_admin_session_key]['uid'],
            'pub_username' => $_SESSION[$G_admin_session_key]['username'],
            'pub_realname' => $_SESSION[$G_admin_session_key]['realname'],
            'pub_time'  => $timestamp,
            'chk_userid' => $_SESSION[$G_admin_session_key]['uid'],
            'chk_username' => $_SESSION[$G_admin_session_key]['username'],
            'chk_realname' => $_SESSION[$G_admin_session_key]['realname'],
            'chk_time'  => $timestamp,
            );
        if($conn->AutoExecute($tbl_article,$rs,'INSERT')) {
            $aid    = $conn->Insert_ID();
        }
    } else {
        $aid    = $rs['aid'];
    }
    redirect($mod_url['modify'] . '&aid=' . $aid);
    exit();
}



function del() {
    global $_TABLES, $cfg_cache;
    $tbl_article = $_TABLES['article'];
    $tbl_collect = $_TABLES['collect'];
    $tbl_attachments = $_TABLES['attachments'];

    $deltype    = trim(@$_POST['deltype']);
    if($deltype == 'all') {
        // 删除POST传递过来的 item_id 
        // 批量删除
        $str_in = array_join_comma($_POST['item_id']);
    } else {
        // get传递过来的删除 单条删除
        $item_id= @(int)$_GET['item_id'];
        $str_in = $item_id;
    }

    if($str_in != '') {
        $conn   = & get_db_conn();
        // 删除和这篇文章有关的图片关联
        $sql    = "UPDATE $tbl_attachments SET item_id = 0 
                                WHERE upmod = 'content'
                                  AND (upvar = 'small_image' || upvar = 'big_image' || upvar LIKE 'userdefparam_%' )
                                  AND item_id IN ({$str_in}) ";
        $conn->Execute($sql);

        // 删除可能存在的该片文章的缓存
        // $cache_file = str_replace('[aid]','',$cfg_cache['content_param_cache_filename']);
        /*
        $delarr = explode(',', $str_in);
        foreach($delarr as $v) {
            $cache_file = $cfg_cache['cache_abspath'] . '/' . str_replace('[aid]',$v,$cfg_cache['content_param_cache_filename']);
            if(file_exists($cache_file)) {
                @unlink($cache_file);
            }
        }
        */


        $sql    = "DELETE FROM $tbl_article 
                    WHERE aid IN ({$str_in}) ";
        if($conn->Execute($sql)) {
            $sql    = "DELETE FROM $tbl_collect WHERE gid IN ({$str_in}) ";
            $conn->Execute($sql);
            
           /*//echo "<script>alert('aa');</script>";*/
			js_success('删除成功！');
        }
    }
}

// 获取所有的列表
function pickup_read($aid) {
    global $_TABLES, $class_var;

    $view_var   = array();
    $tbl_article= $_TABLES['article'];
    $tbl_pickup = $_TABLES['article_pickup'];

    $conn   = & get_db_conn();
    // 通过$aid得到$cid
    if($aid > 0) {
        $sql    = "SELECT aid, cid, article_title FROM $tbl_article WHERE aid = $aid ";
        $ars    = $conn->GetRow($sql);
    } else {
        return false;
    }
    $cid    = @(int)$ars['cid'];
    $ars['class_info']  = get_node_info($GLOBALS[$class_var], $cid);
    $view_var['ars']    = $ars;





    $where  = "WHERE usepickuporder = 1 ";
    if($cid > 0) {
        // 得到所有的父分类id
        $strin  = find_subnode_id($cid, $GLOBALS[$class_var]);
        $strin .= $cid;
        $where  .= "AND cid IN ($strin) OR cid = '0'";
    } else {
        // 未显式指定分类的
        $where  .= "AND cid = '0' ";
    }
    $orderby= "ORDER BY id DESC";


    // 得到具体列表开始
    $sql    = "SELECT * FROM $tbl_pickup 
                $where
                $orderby
                ";
    $rs = $conn->Execute($sql);
    if($rs) 
        $view_var['record'] = $rs->GetRows();
    else 
        $view_var['record'] = array();

    return $view_var;
}


/**
 * 分析上传的文件数组，构造sql
 *
 *
 *
 */
function parse_up_img($img, $var, $oldimg = null, $modifyimg = null) {
    if(is_array($img)) {
        if(array_key_exists('aid', $img)) {
            $img_aid= $img['aid'];
            $imgs   = $img['aid'];
            $img    = $img['destfile'];
        } else {
            $tmp_small_images = '';
            $find_default = false;
            foreach($img as $v) {
                $tmp_small_images .= $v['aid'] . ',';
                if($v['default']) {
                    $tmp_small_image_aid = $v['aid'];
                    $tmp_small_image     = $v['destfile'];
                    $find_default       = true;
                }
            }
            $imgs   = $tmp_small_images;
            if(!$find_default) {
                $img_aid= $img[0]['aid'];
                $img    = $img[0]['destfile'];
            } else {
                $img_aid= $tmp_small_image_aid;
                $img    = $tmp_small_image;
            }
        }
    } else {
        $img    = '';
        $img_aid= 0;
        $imgs   = '';
    }
    return array(
        'update_f'  => "$var, {$var}_aid, {$var}s, ",       // insert into 里的字段
        'update_v'  => "'$img', '$img_aid', '$imgs', ",     // insert into 里的值
        'all_aid'   => $imgs,
        'update'    => "$var = '$img', {$var}_aid = '$img_aid', {$var}s = '$imgs', ",   // update 里的各值
        );
}


// 同步图片
function syn_article_images($aid, $images, $tbl=array()) {
    global $_TABLES, $action;

    $tbl_article        = $_TABLES['article'];
    $tbl_attachments    = $_TABLES['attachments'];

    // 重构 $small_image 和 $big_image
    // 统一一张图片和多张图片的数组结构
    $all_up_image   = '';
    foreach($images as $k => $v) {
        $images[$k] = parse_image_var($v);
        $tmp    = parse_up_img($v, $k);
        $all    = $tmp['all_aid'];
        $all_up_image  .= $all . ',';
    }
    $all_up_image   = conv_valid_instr($all_up_image);

    if($all_up_image != '') {
        $conn   = & get_db_conn();
        // 为刚才上传的文件记录修改上传模块和文章ID字段，记录该文件被用于做什么
        $sql    = "UPDATE $tbl_attachments SET 
                    item_id = '$aid'
                    WHERE aid IN ($all_up_image) ";
        $conn->Execute($sql);
    }


    if($action == 'modify' || substr($action, strrpos($action, '.')+1) == 'modify') {
        foreach($images as $k => $v) {
            $modimg = update_modimg_att($k);
            $images[$k] = empty($v) ? $modimg : array_merge($modimg, $v);
        }
    }

    foreach($images as $k => $v) {
        update_addimg_att($v, $k, $aid, $tbl);
    }

    $flagv  = 2;   // 图片标志
    // 在这里分析如果上传了小图片的文章，设置属性flag加上图片新闻标志，否则去掉
    $conn   = & get_db_conn();
    $ars = $conn->GetRow("SELECT aid, small_image_aid, flag FROM $tbl_article WHERE aid = '$aid' ");
    if($ars) {

        if(@(int)$ars['small_image_aid'] > 0 || (($ars['flag']&$flagv)==$flagv)) {
            // 如果上传了缩略图，或者明确指定了该文章为图片文章
            $flag = ($ars['flag'] | $flagv);
        } else {
            $flag = ($ars['flag'] | $flagv) ^ $flagv;
        }
        $conn->Execute("UPDATE $tbl_article SET flag='$flag' WHERE aid = '$aid' ");
    }
}

function parse_image_var($var) {
    if(is_array($var)) {
        if(@(int)$var['aid'] > 0) {
            return array($var);
        }
    }
    return $var;
}

function update_addimg_att($images, $var, $item_id = 0, $tbl = array()) {
    global $_TABLES, $timestamp, $mod, $action, $class_var, $G_big_integer;


    if($tbl['tbl'] == '') $tbl['tbl'] = $_TABLES['article'];
    if($tbl['pk'] == '') $tbl['pk'] = 'aid';
    $tbl_attachments    = $_TABLES['attachments'];

    $conn   = & get_db_conn();
    if($action == 'modify') {
        // 设置所有的该$item_id的默认为空
        $sql    = "UPDATE $tbl_attachments SET item_default = 0 
                        WHERE item_id = $item_id
                          AND upmod = '$mod'
                          AND upvar = '$var'";
        $conn->Execute($sql);
    }
    // 设置默认图

    //print_r($images);
    $default    = @(int)$_POST['default_' . $var];
    //echo " \$default = $default<br /> ";
    //exit();
    if($default <= 0) $default = 1;


    $db_image       = '';
    $db_image_aid   = 0;
    $db_images      = '';
    if(is_array($images) && sizeof($images) > 0) {
        if(@(int)$images['aid'] > 0) {
            $default_aid    = $images['aid'];
        } else {
            $default_aid    = $images[$default-1]['aid'];
        }

        //echo "default count  = " . ($default-1) . '<BR />';
        $db_image   = $images[$default-1]['destfile'];
        $db_image_aid   = $default_aid;
        /*
        print_r($images);
        echo "\$db_image = $db_image <br />";
        echo "\$db_image_aid = $db_image_aid <br />";
        exit();
        */



        // 设置默认图片
        $sql    = "UPDATE $tbl_attachments SET item_default = 1 WHERE aid = $default_aid";
        //echo $sql;
        $conn->Execute($sql);


        // 这里需要设置“item_id=0”
        // 从$tbl_attachments中找出所有的文件
        // 从中剔除 $images 中没有的
        $sql    = "SELECT aid, fileurl FROM $tbl_attachments WHERE item_id = $item_id AND upmod = '$mod' AND upvar = '$var'";
        $rs = $conn->Execute($sql);
        $rs = $rs->GetRows();

        $delaid = '';
        foreach($rs as $item) {
            $thisaid    = @(int)$item['aid'];
            $find       = false;
            foreach($images as $v) {
                $post_aid = @(int)$v['aid'];
                if($post_aid == $thisaid) {
                    $find = true;
                    break;
                }
            }
            if($find) {
                // 如果找到了，需要构造images字段
                $db_images .= $thisaid . ',';
            } else {
                // 没有找到，需要删除
                $delaid .= $thisaid . ',';
            }
        }
        // 如果是修改，当前台删除了一些图片以后，不需要判断是否修改，因为新增$delaid始终为空
        if($delaid != '') {
            $delaid = substr($delaid, 0, strlen($delaid)-1);
            $sql    = "UPDATE $tbl_attachments SET item_id = 0 WHERE aid IN ($delaid)";
            $conn->Execute($sql);
        }
    } else {
        // 删除了所有的图片
        $sql    = "update $tbl_attachments SET item_id = 0 WHERE item_id = $item_id AND upmod = '$mod' AND upvar = '$var'";
        $conn->Execute($sql);
    }

    // 更新文章字段
    // 这样做好点，虽然大小图分两次处理，但是可以随时增加“图片”字段
    $sql    = "UPDATE {$tbl['tbl']} SET {$var} = '$db_image', {$var}_aid = '$db_image_aid', {$var}s = '$db_images' WHERE {$tbl['pk']} = $item_id ";
    $conn->Execute($sql);
    //echo($sql);
}

function update_modimg_att($var) {
    global $_TABLES, $action, $G_big_integer;

    $tbl_attachments    = $_TABLES['attachments'];


    $arr = array();
    $tmp = @$_POST[$var . '_modaid'];
    if(!is_array($tmp)) return array();
    $icount = 0;
    $sql    = '';
    $conn   = & get_db_conn();
    foreach($tmp as $v) {
        $v  = @(int)$v;
        if($v > 0) {
            $description    = trim($_POST[$var . '_moddescription'][$icount]);
            $item_order     = @(int)$_POST[$var . '_modorder'][$icount];
            if($item_order <=0 || $item_order >= $G_big_integer) {
                $item_order = $G_big_integer;
            }
            $arr[]  = array(
                'aid'           => $v,
                'destfile'      => trim($_POST[$var . '_fileurl'][$icount]),
                'item_order'    => $item_order,
                'description'   => $description,
                );
            // 更新描述和排序
            $sql    = "UPDATE $tbl_attachments SET description = '$description', item_order='$item_order' WHERE aid = '$v'";
            $conn->Execute($sql);
        }
        $icount ++;
    }
    return $arr;
}

function get_html_img_record($in, $input_name) {
    global $_TABLES, $G_web_upload, $G_big_integer;


    $str= '';
    $icount = 1;
    if($in != '') {
        $conn   = & get_db_conn();
        // 如果传递过来的变量中有数据
        $in = $in . '0';
        $sql    = "SELECT * FROM " . $_TABLES['attachments'] . " WHERE aid IN ( $in ) 
                    ORDER BY item_order ASC, aid ASC ";
        $rs = $conn->Execute($sql);
        $rs = $rs->GetRows();
        foreach($rs as $items) {
            $fileid     = $items['aid'];
            $filename   = $items['filename'];
            $db_fileurl = $items['fileurl'];
            $fileurl    = $G_web_upload . $db_fileurl;
            $description= $items['description'];
            $chk_this   = $items['item_default'] == 1 ? 'checked' : '';
            $item_order = @(int)$items['item_order'];
            if($item_order <= 0 || $item_order >= $G_big_integer) $item_order = '';
            $str   .= <<<EOT
    <TR>
        <TD><SPAN id="{$input_name}_{$icount}">
    [<a href="javascript:void(0);" onclick="return del_upload_file(this.parentNode.parentNode.parentNode.rowIndex, '$input_name');">删除</a>]&nbsp;&nbsp;<INPUT TYPE="radio" NAME="default_{$input_name}" ID="default_{$input_name}_{$icount}" value="$icount" onclick="return default_img(this, '$fileurl', '$input_name');" $chk_this> 
    <label for="default_{$input_name}_{$icount}">默认</label>&nbsp;&nbsp;
    <a href="$fileurl" target="_blank">$filename</a>

        <INPUT TYPE="hidden" NAME="{$input_name}_fileurl[]" value="$db_fileurl">

        </SPAN><input type="hidden" name="{$input_name}_modaid[]" value="$fileid"></TD>
        <TD><input type="text" name="{$input_name}_modorder[]" id="{$input_name}_modorder[]" value="$item_order" size="3" class="text"></TD>
        <TD><input type="text" name="{$input_name}_moddescription[]" id="{$input_name}_moddescription[]" value="$description" size="12" class="text"></TD>
    </TR>
EOT;
            $icount ++;
        }
    }

    // 构造整个上传表格
    $str  = <<<EOT
<TABLE border="0" cellpadding="2" cellspacing="0" id="{$input_name}_table" width="100%" style="width:98%">
<TR>
    <TD width="240">上传图片</TD>
    <TD>排序</TD>
    <TD>描述</TD>
</TR>
$str
<TR>
    <TD><SPAN id="{$input_name}_$icount"></SPAN><INPUT TYPE="file" NAME="{$input_name}[]" class="text" size="12" onchange="upload_onchange(this)"></TD>
    <TD><input type="text" name="{$input_name}_order[]" id="{$input_name}_order[]" value="" size="3" class="text"></TD>
    <TD><input type="text" name="{$input_name}_description[]" id="{$input_name}_description[]" value="" size="12" class="text"></TD>
</TR>
</TABLE>
EOT;

    // 初始化当前行数计数器
    $str   .= <<<EOT
<SCRIPT LANGUAGE="JavaScript">
<!--
var n_{$input_name}_table_trnum = {$icount};
var n_{$input_name}_table_anum  = {$icount};
//-->
</SCRIPT>
EOT;
    return $str;
}
function echo_html_img_js() {
    /** 
     * var file_name = file_path.substr(file_path.lastIndexOf('\\\\')+1);
     * 在html页面上是
     * var file_name = file_path.substr(file_path.lastIndexOf('\\')+1);
     * 但是在php字符串中反斜线要转义，所以多加了一个。
     */
    echo <<<EOT
<SCRIPT LANGUAGE="JavaScript">
<!--
function upload_onchange(ofile) {
    var upload_var= ofile.name;
    ofile.style.display = 'none';
    upload_var = upload_var.substr(0,upload_var.length-2);

    var file_path = ofile.value;
    file_path = file_path.replace(/\\\\/g, '/');
    var file_name = file_path.substr(file_path.lastIndexOf('/')+1);


    eval('o_' + upload_var + '_table = GE("'+upload_var+'_table");');
    eval('if(typeof(n_' + upload_var + '_table_trnum)=="undefined")n_' + upload_var + '_table_trnum=1');
    eval('var trnum = n_' + upload_var + '_table_trnum');
    eval('var anum = n_' + upload_var + '_table_anum');
    eval('var row = o_' + upload_var + '_table.insertRow()');

    eval('var chk_default_this = trnum == 1 ? " checked" : ""; ');

    var str='[<a href="javascript:void(0);" onclick="return del_upload_file(this.parentNode.parentNode.parentNode.rowIndex, \'' + upload_var + '\');">删除</a>]&nbsp;&nbsp;'+
            '<INPUT TYPE="radio" NAME="default_' + upload_var + '" ID="default_' + upload_var + '_' + trnum + '" value="' + trnum + '" onclick="return default_img(this, \'file:///'+file_path+'\', \''+upload_var+'\');" ' + chk_default_this + '>' + 
            ' <label for="default_'+upload_var+'_' + trnum + '">默认</label>&nbsp;&nbsp;' + 
            ' <a href="file:///'+file_path+'" target="_blank">'+file_name+'</a>';
    //alert(str);
    //eval('alert('+trnum+');');
    eval('GE("'+upload_var+'_'+anum+'").innerHTML=str;');

    cell0 = row.insertCell();
    cell1 = row.insertCell();
    cell2 = row.insertCell();

    cell0.innerHTML = '<SPAN id="'+upload_var+'_'+(anum+1)+'"></SPAN>' + 
                        '<input type="file" name="' + upload_var + '[]" value="" class="text" size="12" onchange="upload_onchange(this)">';
    cell1.innerHTML = '<input type="text" name="' + upload_var + '_order[]" value="" size="3" class="text">'
    cell2.innerHTML = '<input type="text" name="' + upload_var + '_description[]" value="" size="12" class="text">'


    eval('n_' + upload_var + '_table_trnum ++;');
    eval('n_' + upload_var + '_table_anum ++;');
}

function del_upload_file(id, upload_var) {
    eval('o_del_table=GE("'+upload_var+'_table");o_del_table.deleteRow('+id+');n_'+upload_var+'_table_trnum --;');
}
function default_img(chkobj, img, upload_var) {
    if(chkobj.checked) {
        eval('GE("obj_'+upload_var+'").src="'+img+'";');
    }
}
//-->
</SCRIPT>

EOT;
}

function content_param($aid, $param) {
    // 暂不处理自定义字段
}
?>